/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: bjc
 * Date: 2025-11-09
 * Time: 21:42
 */
public class Test01_minSubArrayLen {
    public static int minSubArrayLen(int target, int[] nums) {
        int left = 0,right = 0;
        int sum = 0;
        int ret = Integer.MAX_VALUE;
        while(right < nums.length){
            sum += nums[right];
            while(sum >= target){
                ret = Math.min(ret,right-left+1);
                //此时已经满足条件，然后移动right只会越来越大，因为数组都是正整数，所以此时不用移动right，因为不会是最小长度了
                sum -= nums[left];//更新sum的值
                left++;
            }
            right++;
        }
        return ret == Integer.MAX_VALUE ? 0 : ret;

    }
    public static void main(String[] args) {
        int[] nums = {2,3,1,2,4,3};
        int target = 7;
        System.out.println(minSubArrayLen(target,nums));
    }
}
